
//==============================================================================Assault

KitEquip_Assault(playerid)
{
	if(TotalSupplies[playerid]==1)
	{
	    new Float:pPos[4];
	    GetPlayerPos(playerid, pPos[0], pPos[1], pPos[2]);
	    GetPlayerFacingAngle(playerid, pPos[3]);

		ApplyAnimation(playerid, "grenade", "WEAPON_throwu", 4.0, 0, 0, 0, 0, 0, 1);
		GetXYInFrontOfPlayer(playerid, pPos[0], pPos[1], 0.6);
		AddSupplyCrate(pPos[0], pPos[1], pPos[2]-0.9, pPos[3], playerid);
		Streamer_Update(playerid);
		TotalSupplies[playerid]--;
		UpdateEqipmentText(playerid);
		SetTimerEx("ResetKitEquip", 8000, false, "d", playerid);
	}
}

//==============================================================================Medic

KitEquip_Medic(playerid)
{
	if(TotalHeal[playerid]==1)
	{
	    PlayerLoop(i)
	    {
			if(IsPlayerInDynamicArea(playerid, PlayerProximity[i]))
			{
				if(bPlayerDeathmatchSettings[i]&BleedingOut)Medic_revive(playerid, i);
				else Medic_heal(playerid, i);
				UpdateEqipmentText(playerid);
			}
		}
	}
}
Medic_revive(playerid, targetid)
{
	TogglePlayerControllable(targetid, true);
	ApplyAnimation(playerid, "bomber", "bom_Plant", 4.0, 0, 0, 0, 0, 0, 1);
	ApplyAnimation(targetid, "ped", "getup", 4.0, 0, 0, 0, 0, 0, 1);
	TotalHeal[playerid]--;
	SetTimerEx("Medic_RevivePlayer", 2000, false, "dd", playerid, targetid);
}
public Medic_RevivePlayer(playerid, targetid)
{
	SetPlayerHealth(targetid, MAX_HEALTH);
	SetCameraBehindPlayer(targetid);

	ExitBleedOut(targetid);
	GiveXP(playerid, 10, "Revive");
	
	ClearAnimations(playerid, 1);
	ClearAnimations(targetid, 1);

	SetTimerEx("ResetKitEquip", 8000, false, "d", playerid);
	bitTrue(bPlayerGameSettings[playerid], UsingEquipment);
}
Medic_heal(playerid, targetid)
{
	new Float:iPH;
	GetPlayerHealth(playerid, iPH);
	if(iPH < (MAX_HEALTH*0.8))GiveXP(playerid, 10, "healing");

	GivePlayerHealth(targetid, MAX_HEALTH*0.4);
	ApplyAnimation(playerid, "ped", "atm", 4.0, 0, 0, 0, 0, 2000, 1);
	SetPlayerToFacePlayer(playerid, targetid);

	TotalHeal[playerid]--;
	SetTimerEx("ResetKitEquip", 8000, false, "d", playerid);
}

//==============================================================================Sniper

KitEquip_Sniper(playerid)
{
	if(TotalMines[playerid]>0)
	{
		ApplyAnimation(playerid, "bomber", "bom_Plant", 4.0, 1, 0, 0, 0, 2000, 1);
		SetTimerEx("Sniper_PlaceMine", 1500, false, "i", playerid);
		TotalMines[playerid]--;
		bitTrue(bPlayerGameSettings[playerid], UsingEquipment);
		UpdateEqipmentText(playerid);
	}
}
public Sniper_PlaceMine(playerid)
{
	new
		Float:x,
		Float:y,
		Float:z;
	GetPlayerPos(playerid, x, y, z);
	GetXYInFrontOfPlayer(playerid, x, y, 0.6);
	CreateMine(playerid, x, y, z-0.9);
	bitFalse(bPlayerGameSettings[playerid], UsingEquipment);
}

//==============================================================================Engineer

KitEquip_Engineer(playerid)
{
	if(TotalRepair[playerid]==1)
	{
		new Float:vX, Float:vY, Float:vZ, Float:vH, vehicleID;
		vehicleID = GetNearestVehicle(playerid);
		GetVehiclePos(vehicleID, vX, vY, vZ);
		GetVehicleHealth(vehicleID, vH);
		if(IsPlayerInRangeOfPoint(playerid, 5, vX, vY, vZ))
		{
			if(vH > 800) msg(playerid, ORANGE, "Does not need fixing");
			else
			{
				TogglePlayerControllable(playerid, false);
				SetTimerEx("Engineer_Repair", 3000, false, "dd", playerid, vehicleID);
				ApplyAnimation(playerid, "BOMBER", "BOM_Plant", 4.0, 1, 0, 0, 0, 3000, 1);
				TotalRepair[playerid]--;
				bitTrue(bPlayerGameSettings[playerid], UsingEquipment);
			}
		}
		UpdateEqipmentText(playerid);
	}
}
public Engineer_Repair(playerid, vehicleid)
{
	SetVehicleHealth(vehicleid, 1000);
	ApplyAnimation(playerid, "BOMBER", "BOM_Plant_Crouch_Out", 4.0, 0, 0, 0, 0, 0, 1);
	GiveXP(playerid,5,"repair");
	msg(playerid,LGREEN,"Vehicle Repaired!");
	TogglePlayerControllable(playerid,true);
	SetTimerEx("RefilRepair", 10000, false, "d", playerid);
	bitFalse(bPlayerGameSettings[playerid], UsingEquipment);
}

//==============================================================================Functions


public ResetKitEquip(playerid)
{
	if(pKit(playerid) == KIT_ASSAULT)TotalSupplies[playerid]=1;
	if(pKit(playerid) == KIT_MEDIC)TotalHeal[playerid]=1;
	if(pKit(playerid) == KIT_ENGINEER)TotalRepair[playerid]=1;
	UpdateEqipmentText(playerid);
}

UpdateEqipmentText(pid)
{
	if(!(bDeathmatchSettings&EquipmentUsage))
	{
		TextDrawSetString(SpecialWeps[pid], " ");
		return 0;
	}
	new szEquipTxt[20];
	if(pKit(pid)==0)
	{
		new SuppliesReady[16]="~y~Ready";
		if(TotalSupplies[pid]==0)SuppliesReady="~r~Wait...";
		format(szEquipTxt, 20, "Supplies: %s", SuppliesReady);
	}
	if(pKit(pid) == 1)
	{
		new HealReady[16]="~y~Ready";
		if(TotalHeal[pid]==0) HealReady="~r~Wait...";
		format(szEquipTxt, 20, "Morphine: %s", HealReady);
	}
	if(pKit(pid) == 2)
	{
		format(szEquipTxt, 20, "Mines: %d", TotalMines[pid]);
	}
	if(pKit(pid) == 3)
	{
		new RepairKitReady[16]="~y~Ready";
		if(TotalRepair[pid]>=1)RepairKitReady="~r~Wait...";
		format(szEquipTxt, 20, "Repair: %s", RepairKitReady);
	}
	TextDrawSetString(SpecialWeps[pid], szEquipTxt);
	return 1;
}

